package com.zucc.eye.dto;

import com.alibaba.fastjson.JSONObject;
import com.zucc.eye.entity.Comment;
import com.zucc.eye.entity.Issue;
import com.zucc.eye.entity.Reactions;
import com.zucc.eye.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @description comment
 * @author zhengkai.blog.csdn.net
 * @date 2022-02-09
 */
//@Entity
@Data
//@Table(name="comment")
@ApiModel("comment")
public class CommentDto implements Serializable {

    private static final long serialVersionUID = 1L;

    public Comment toEntity(){
        //Repo repo = new Repo();
        //Issue issue = new Issue();
        Comment obj = new Comment();
        BeanUtils.copyProperties(this,obj);
        //一个实体没办法复制吧
        //String stringOwner = JSONObject.toJSONString(owner);
        //owner
        //assignees
        //labels
        //reactions
        //user

        obj.setReactions( JSONObject.toJSONString(reactions));
        obj.setUser( JSONObject.toJSONString(user));
        //obj.setUser( JSONObject.toJSONString(user));
        return obj;
    }
//    @Id
//    @GeneratedValue
    @Id
    @ApiModelProperty("id")
    //@GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    /**
    * user_name
    */
    @ApiModelProperty("user_name")
    @Column(name="user_name")
    private String userName;

    /**
    * user_url
    */
    @ApiModelProperty("user_url")
    @Column(name="user_url")
    private String userUrl;

    /**
    * user_avatar
    */
    @ApiModelProperty("user_avatar")
    @Column(name="user_avatar")
    private String userAvatar;

    /**
    * date
    */
    @ApiModelProperty("date")
    @Column(name="date")
    private Date date;

    /**
    * url
    */
    @ApiModelProperty("url")
    @Column(name="url")
    private String url;

    /**
    * body
    */
    @ApiModelProperty("body")
    @Column(name="body")
    private String body;

    /**
    * issue_id
    */
    @ApiModelProperty("issue_id")
    @Column(name="issue_id")
    private Integer issueId;

    /**
    * html_url
    */
    @ApiModelProperty("html_url")
    @Column(name="html_url")
    private String htmlUrl;

    /**
    * issue_url
    */
    @ApiModelProperty("issue_url")
    @Column(name="issue_url")
    private String issueUrl;

    /**
    * node_id
    */
    @ApiModelProperty("node_id")
    @Column(name="node_id")
    private String nodeId;

    /**
    * user
    */
//    @ApiModelProperty("user")
//    @Column(name="user")
//    private String user;

//    @ApiModelProperty("user")
////    @Column(name="user")
//    @Type(type = "json")
//    @Column(name="user",columnDefinition = "json" )
////    private String user;
//    private User user;

//    @ApiModelProperty("user")
////    @Column(name="user")
////    @Type(type = "json")
//    @Type(type = "com.zucc.eye.entity.User")
////    @Type org.hibernate.annotations
////    https://www.cnblogs.com/aishangtaxuefeihong/p/6580630.html
////    https://www.cnblogs.com/powerwu/articles/10564004.html
//    @Column(name="user",columnDefinition = "json" )
////    private String user;
//    private User user;


    @ApiModelProperty("user")
    @Column(name="user")
    //private String user;
    private User user;



//    @ApiModelProperty("reactions")
////    @Column(name="reactions")
////    @Type(type = "json")
//    @Type(type = "com.zucc.eye.entity.Reactions")
////    @Column(columnDefinition = "json" )
////    name 不能不写
//    @Column(name="reactions",columnDefinition = "json" )
////    private String reactions;
//    private Reactions reactions;

    @ApiModelProperty("reactions")
    @Column(name="reactions")
    //private String reactions;
    private Reactions reactions;



    /**
    * created_at
    */
    @ApiModelProperty("created_at")
    @Column(name="created_at")
    private Date createdAt;

    /**
    * updated_at
    */
    @ApiModelProperty("updated_at")
    @Column(name="updated_at")
    private Date updatedAt;

    /**
    * author_association
    */
    @ApiModelProperty("author_association")
    @Column(name="author_association")
    private String authorAssociation;

    /**
    * reactions
    */
//    @ApiModelProperty("reactions")
//    @Column(name="reactions")
//    private String reactions;

//    @ApiModelProperty("reactions")
////    @Column(name="reactions")
//    @Type(type = "json")
////    @Column(columnDefinition = "json" )
////    name 不能不写
//    @Column(name="reactions",columnDefinition = "json" )
////    private String reactions;
//    private Reactions reactions;

    /**
    * performed_via_github_app
    */
    @ApiModelProperty("performed_via_github_app")
    @Column(name="performed_via_github_app")
    private Integer performedViaGithubApp;

    public CommentDto() {
    }

    public CommentDto(Comment comment) {
        //CommentDto commentDto = new CommentDto();
        BeanUtils.copyProperties(comment,this);
        //setReactions();
        //List<String[]> strings = JSONObject.parseArray(comment.getReactions(), String[].class);
        //List<String> list = JSONObject.parseArray(comment.getReactions(), String.class);
        Reactions reactions = JSONObject.parseObject(comment.getReactions(), Reactions.class);
        User user = JSONObject.parseObject(comment.getReactions(), User.class);
        setReactions(reactions);
        setUser(user);

    }

}